package com.future.esdemo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.future.esdemo.domain.TaskAll;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author future
 * @title: TaskMapper
 * @description: 任务all 数据访问
 * @date 2022-03-30 10:32
 */
@SuppressWarnings("all")
public interface TaskAllMapper extends BaseMapper<TaskAll> {

    @Update("<script>update task_all set executeCount = 0 where id = #{id}</script>")
    int resetPendingTask(String id);

    @Update("<script>update task_all set priority = 101 where id = #{taskId}</script>")
    void promotePriority(String taskId);



    /**
     * 更新已挂起任务状态为已完成
     *
     * @param taskId
     * @return
     */
    @Update("<script>update task_all set status = 2 where id = #{taskId} and status = 3 </script>")
    int updateStateFailed2Finished(String taskId);

    /**
     * 更新已挂起任务状态为待处理
     *
     * @param taskId
     * @return
     */
    @Update("<script>update task_all set status = 0 where id = #{taskId} and status = 3 </script>")
    int updateStateFailed2Pending(String taskId);

    @Update("<script>update task_all set status  = 2,executeTime = #{executingTime},executorId =#{executorId},executeCount = executeCount +1  where id = #{taskId}</script>")
    int updateStatePending2Executing(@Param("taskId") String taskId, @Param("executorId") String executorId, @Param("executingTime") Date executingTime);

    /**
     * 查询全部任务分页
     */
    List listAllTask(Map param);

    /**
     * 查询全部任务记录数
     */
    Integer countAllTask(Map param);

}
